//
//  EpointSampleNavViewController.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-7-18.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "EpointSampleNavViewController.h"
#import "EpointSampleTask.h"
#import "EpointFunDataModel.h"
#import "EpointSinglePickerViewController.h"

@interface EpointSampleNavViewController ()
{
    UITableView *tv;
    NSMutableArray *tvdata;
}
@end

@implementation EpointSampleNavViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"Home";
    tvdata = [[NSMutableArray alloc]init];
    EpointFunDataModel *themeswitch = [[EpointFunDataModel alloc]initWithTitle:@"主题切换" action:^{
        NSArray *colorTitles = [NSArray arrayWithObjects:@"浪漫紫",@"橙色", nil];
        NSArray *color = [NSArray arrayWithObjects:COLOR(91, 68, 106),[UIColor orangeColor], nil];
        [EpointSinglePickerViewController InvokeSinglePickerViewController:self title:@"选择" strArr:colorTitles handler:^(int index){
            [self.navigationController.navigationBar setBackgroundImage:[EpointUIUtils getImageByColor:[color objectAtIndex:index]] forBarMetrics:UIBarMetricsDefault];
        }];
        
    }];
    [tvdata addObject:themeswitch];
    
    EpointFunDataModel *hidnav = [[EpointFunDataModel alloc]initWithTitle:@"导航隐藏与显示" action:^{
        BOOL navBarState = [self.navigationController isNavigationBarHidden];
        [self.navigationController setNavigationBarHidden:!navBarState animated:YES];
    }];
    [tvdata addObject:hidnav];
    
    tv = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tv.delegate = self;
    tv.dataSource = self;
    [self.view addSubview:tv];
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    EpointFunDataModel *m = [tvdata objectAtIndex:indexPath.row];
    cell.textLabel.text = m.title;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tvdata.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EpointFunDataModel *m = [tvdata objectAtIndex:indexPath.row];
    m.action();
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)refreshUIWithThreadGuid:(int)taskId andData:(NSObject *)obj
{
    if (taskId==1) {
        
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
